<template>
  <customTree
    ref="customTree"
    :data="treeData"
    @click="click"
    :defaultActived="defaultActived"
    :expand-level="expandLevel"
    :checkable="checkable"
    :keys="{ value: 'id', label: 'title', children: 'children' }"
    :subHeight="202"
  />
</template>

<script>

export default {
  desc: '医院商品分类树',
  name: 'hospitalCategory',
  components: {
  },
  props: {
    /**
     * @Description：默认选中节点
     * @Date 2023-10-10
     * @param [节点value值]
     */
    defaultActived: {
      type: Array,
      default: () => {
        return [0]
      }
    },
    /**
     * @Description：默认展开第几级节点
     * @Date 2023-10-10
     */
    expandLevel: {
      type: Number,
      default: () => 1,
    },
    /**
     * @Description：显示复选框
     * @Date 2023-10-20
     */
    checkable: {
      type: Boolean,
      default: () => {
        return false
      }
    }
  },
  created() {
    this.load()
  },
  data() {
    return {
      treeData: []
    }
  },
  methods: {
    // 加载数据
    load() {
      this.$ajax.get('base/hospital_catalogs/tree?autoAddRoot=true', {}).then(response => {
        if (response.code == 0) {
          this.treeData = response.data
        } else {
          this.utilMessage.error(response.msg)
        }
      })
    },

    // 节点点击时触发
    click(nodeData) {
      this.$emit('click', nodeData)
    },

    // 树实例
    getInst() {
      return this.$refs.customTree
    }
  },
  watch: {
  },
  computed: {
  }
}
</script>

<style lang="scss">
</style>
